package br.com.caelum.vraptor.controller;

import javax.inject.Inject;

import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.anotations.Administracao;
import br.com.caelum.vraptor.componentes.AdministradorOn;
import br.com.caelum.vraptor.dao.AdministradorDAO;
import br.com.caelum.vraptor.dao.FuncionarioDAO;
import br.com.caelum.vraptor.entidades.Administrador;

@Controller
public class AdministracaoController {
	@Inject
	private Result result;
	@Inject
	private AdministradorDAO dao;
	@Inject
	private FuncionarioDAO fdao;
	@Inject
	private AdministradorOn administradorOn;
	@Administracao
	public void base(){
		result.include("funcionarioList", fdao.find());
	}
	public void login(){
		Administrador admin = new Administrador();
		admin.setId(1);
		admin.setLogin("admin");
		admin.setSenha("admin");
		dao.save(admin);
		
	}
	public void logar(String login, String senha){
		Administrador admin = dao.find(login, senha);
		System.out.println("wwww");
		if(admin==null){result.redirectTo(CarteirasController.class).error();}
		else{
		 administradorOn.login(admin);
		 result.redirectTo(this).base();
		}
		
	}

}
